package com.itcast.donkey.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.itcast.donkey.activity.InFigureActivity;
import com.itcast.donkey.modles.TravelFigureModels;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/9/1.
 */
public class FigureAdapter extends StaticPagerAdapter {
    private Context context;
    private ArrayList<TravelFigureModels> travelFigureModelsArrayList = new ArrayList<>();

    public FigureAdapter(Context context, ArrayList<TravelFigureModels> travelFigureModelsArrayList) {
        this.context = context;
        this.travelFigureModelsArrayList = travelFigureModelsArrayList;
    }

    @Override
    public View getView(ViewGroup container, int position) {
        ImageView view = new ImageView(container.getContext());
        Picasso.with(context).load(travelFigureModelsArrayList.get(position).getImage_url()).into(view);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, InFigureActivity.class);
                context.startActivity(intent);
            }
        });
        return view;
    }


    @Override
    public int getCount() {
        return travelFigureModelsArrayList.size();
    }
}
